package net.mishna.ui.widgets;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

/**
 * A special {@link Button} that does not turn into the pressed state when when
 * the parent is already pressed.
 * 
 * @author Cyril Mottier
 * 
 */
public class DontPressWithParentButton extends ImageView
{

    public DontPressWithParentButton(Context context)
    {
	super(context);
    }

    public DontPressWithParentButton(Context context, AttributeSet attrs)
    {
	super(context, attrs);
    }

    public DontPressWithParentButton(Context context, AttributeSet attrs, int defStyle)
    {
	super(context, attrs, defStyle);
    }

    @Override
    public void setPressed(boolean pressed)
    {
	// Make sure the parent is a View prior casting it to View
	if (pressed && getParent() instanceof View && ((View) getParent()).isPressed())
	{
	    return;
	}
	super.setPressed(pressed);
    }

}
